package com.lhf.fvsmain.controller;

import com.github.pagehelper.PageInfo;
import com.lhf.fvscommon.entity.SysRole;
import com.lhf.fvscommon.vo.SysPerOptionsVo;
import com.lhf.fvscommon.vo.SysRoleTableVo;
import com.lhf.fvscore.annotation.ResultBody;
import com.lhf.fvssystem.service.SysRoleService;
import io.swagger.annotations.*;
import org.springframework.stereotype.Indexed;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色表(SysRole)表控制层
 *
 * @author lhf
 * @since 2020-10-26 10:56:48
 */
@RestController
@RequestMapping("sysRole")
@Api(tags = "")
@ResultBody
public class SysRoleController {
    /**
     * 服务对象
     */
    @Resource
    private SysRoleService sysRoleService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation(value = "查询", notes = "查询单条记录")
    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功"),
            @ApiResponse(code = 500, message = "服务端异常")
    })
    @ResultBody(code = 111)
    public SysRole selectOne(Integer id) {
        return this.sysRoleService.queryById(id);
    }


    @PostMapping("/insert")
    @ApiOperation(value = "添加", notes = "添加单条记录")
    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功"),
            @ApiResponse(code = 500, message = "服务端异常")
    })
    public SysRole insert(@RequestBody SysRole entity) {
        return this.sysRoleService.insert(entity);
    }


    @PutMapping("update")
    @ApiOperation(value = "修改", notes = "修改单体条记录")
    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功"),
            @ApiResponse(code = 500, message = "服务端异常")
    })
    public SysRole update(@RequestBody SysRole entity) {
        return this.sysRoleService.update(entity);
    }

    @DeleteMapping("delete/{id}")
    @ApiOperation(value = "删除", notes = "删除单条记录")
    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功"),
            @ApiResponse(code = 500, message = "服务端异常")
    })
    public boolean delete(@PathVariable Integer id) {
        return this.sysRoleService.deleteById(id);
    }

//    @GetMapping("table")
//    @ApiOperation(value = "查询", notes = "查询表结构")
//    @ApiResponses({
//            @ApiResponse(code = 200, message = "请求成功"),
//            @ApiResponse(code = 500, message = "服务端异常")
//    })
//
//    public PageInfo<SysRoleTableVo> selectTable(SysRole role) {
//        return this.sysRoleService.selectTable(role);
//    }

    @GetMapping("hasRole/{role}")
    @ApiOperation(value = "查询", notes = "查询是否存在该角色")
    public boolean hasRole(@PathVariable String role) {
        return this.sysRoleService.hasRole(role);
    }


    @PostMapping("addPer/{roleId}")
    @ApiOperation(value = "添加", notes = "角色添加权限")
    public boolean addPer(@RequestBody String perIds, @PathVariable Integer roleId) {
        return this.sysRoleService.addPer(perIds, roleId);
    }

}